
$(function() {
	searchEntity();
});

//查询检索列表和左侧我的项目状态
function searchEntity() {
	var searchText = $("#searchText").val();
	var searchStatus = $("#searchStatus").val();
	$.ajax({
	  url: 'project!searchVersionListByOrgUser.action',
	  type: 'post',
	  data: {
	  	"searchText": searchText,
	  	"searchStatus": searchStatus
	  },
	  dataType: 'json',
	  success: function(data) {
		  Interceptor(data);
	  	 // 左侧
	  	 $("#province_h2").html(data[0].user.province.name);
	  	 $("#org_ul").html('<li><a href="javascript:void(0)">' + data[0].user.organization.name + '</a></li>');
	     // 列表
	     var resultContent = '<tr>'
					          + '<th scope="col" width="100">注册号</th>'
					          + '<th scope="col">项目名称</th>'
					          + '<th scope="col" width="70">变更状态</th>'
					          + '<th scope="col" width="70">变更日期</th>'
					          + '<th scope="col" width="85">变更用户</th>'
					          + '<th scope="col" width="60">版本号</th>'
					          + '<th scope="col" width="70">操作</th>'
					          + '</tr>';
	     $(data[0].list).each(function(i) {
	     		var statusStr = '';
	     		var operaStr = '';
	     		var trStr = '';
	     		if(i%2==0) {
	     			trStr = 'class="odd"';
	     		}
	     		if(data[0].list[i].versionStatus=='0') {
	     			statusStr = '待审查';
	     			operaStr = '<a href="javascript:void(0)" onclick="if(confirm(\'您确定要进行此操作吗?\')) passAuditProjectVersion(' 
	     			+ data[0].list[i].versionId + ');">通过</a><br><a href="project_version_reason.jsp?&status=2&id='
	     			+ data[0].list[i].versionId +'">不通过</a><br>';
	     		}else {
	     			statusStr = '';
	     			operaStr = '';
	     		}
				resultContent += '<tr ' + trStr +  '>'
                            	+ '<td height="30">' + data[0].list[i].regNumber + '</td>'
                                + '<td><h2><a href="/index/project_detail.jsp?id=' + data[0].list[i].id + '">' + data[0].list[i].name + '</a></h2></td>'
                                + '<td align="center" style="color: red;">' + statusStr + '</td>'
                                + '<td align="center">' + data[0].list[i].versionTime.substring(0,10) + '</td>'
                                + '<td align="center">' + data[0].list[i].createUser.name + '</td>'
                                + '<td align="center">Version' + data[0].list[i].versionNumber 
                                + '<br><a href="project_version_find.jsp?id=' + data[0].list[i].versionId + '">当前变更</a><br><a href="project_version.jsp?id=' + data[0].list[i].id + '">历史变更</a></td>'
                                + '<td align="center">' + operaStr + '</td>'
                                + '</tr>';
		 });
		 
		 if(data[0].list==null || data[0].list=='') {
		 	resultContent += '<tr><td colspan="7" height="30">暂无信息！</td></tr>'
		 }
		 $("#mainData").html(resultContent); 
	  }, 
	  error: function() {
		  //
	  }
    });
}

function statusHandle(value){
	$("#searchStatus").val(value);
	searchEntity();
}

function passAuditProjectVersion(id) {
	$.ajax({
		url : 'project!auditProjectVersion.action',
		dataType: 'html',
		data:{
			"id": id,
			"reason": "",
			"status": "1"
		},
		success : function(data) {
			Interceptor(data);
		     if(data!=null && data=="success") {
		    	alert("操作成功！");
		    	searchEntity();
		     }
		},
		error : function() {
			alert("通信失败！");
		}
	 });
}

